<template>
  <el-form label-width="100px" label-position="left">
    <el-form-item label="图层名称" prop="layerName">
      <el-input
        v-model.trim="formData.layerName"
        size="default"
        style="width: 100%"
        @change="changed($event, 'layerName')"
      />
    </el-form-item>
    <el-form-item label="背景颜色" prop="backgroundColor">
      <ColorPicker
        v-model.trim="formData.backgroundColor"
        @change="(val) => changed(val, 'backgroundColor')"
      />
    </el-form-item>
    <el-collapse>
      <el-collapse-item title="柱状图设置" name="1">
        <el-form-item label="柱条颜色" prop="barColor">
          <ColorPicker
            v-model.trim="formData.barColor"
            @change="(val) => changed(val, 'barColor')"
          />
        </el-form-item>
        <el-form-item label="文字颜色" prop="barLabelFontColor">
          <ColorPicker
            v-model.trim="formData.barLabelFontColor"
            @change="(val) => changed(val, 'barLabelFontColor')"
          />
        </el-form-item>
        <el-form-item label="文字大小" prop="barLabelFontSize">
          <el-input-number
            v-model.trim="formData.barLabelFontSize"
            size="default"
            style="width: 100%"
            controls-position="right"
            @change="changed($event, 'barLabelFontSize')"
          />
        </el-form-item>
      </el-collapse-item>
      <el-collapse-item title="盒须图设置" name="2">
        <el-form-item label="盒须颜色" prop="boxplotColor">
          <ColorPicker
            v-model.trim="formData.boxplotColor"
            @change="(val) => changed(val, 'boxplotColor')"
          />
        </el-form-item>
      </el-collapse-item>
      <el-collapse-item title="自定义图设置" name="3">
        <el-form-item label="形状颜色" prop="rectColor">
          <ColorPicker
            v-model.trim="formData.rectColor"
            @change="(val) => changed(val, 'rectColor')"
          />
        </el-form-item>
      </el-collapse-item>
      <el-collapse-item title="标题设置" name="11">
        <el-form-item label="标题颜色" prop="titleColor">
          <ColorPicker
            v-model.trim="formData.titleColor"
            @change="(val) => changed(val, 'titleColor')"
          />
        </el-form-item>
        <el-form-item label="文字大小" prop="titleFontSize">
          <el-input-number
            v-model.trim="formData.titleFontSize"
            size="default"
            style="width: 100%"
            controls-position="right"
            @change="changed($event, 'titleFontSize')"
          />
        </el-form-item>
      </el-collapse-item>
      <el-collapse-item title="副标题设置" name="12">
        <el-form-item label="副标题颜色" prop="subtitleColor">
          <ColorPicker
            v-model.trim="formData.subtitleColor"
            @change="(val) => changed(val, 'subtitleColor')"
          />
        </el-form-item>
        <el-form-item label="文字大小" prop="subtitleFontSize">
          <el-input-number
            v-model.trim="formData.subtitleFontSize"
            size="default"
            style="width: 100%"
            controls-position="right"
            @change="changed($event, 'subtitleFontSize')"
          />
        </el-form-item>
      </el-collapse-item>
      <el-collapse-item title="图例设置" name="13">
        <el-form-item label="图例颜色" prop="legendColor">
          <ColorPicker
            v-model.trim="formData.legendColor"
            @change="(val) => changed(val, 'legendColor')"
          />
        </el-form-item>
        <el-form-item label="文字颜色" prop="legendFontColor">
          <ColorPicker
            v-model.trim="formData.legendFontColor"
            @change="(val) => changed(val, 'legendFontColor')"
          />
        </el-form-item>
        <el-form-item label="文字大小" prop="legendFontSize">
          <el-input-number
            v-model.trim="formData.legendFontSize"
            size="default"
            style="width: 100%"
            controls-position="right"
            @change="changed($event, 'legendFontSize')"
          />
        </el-form-item>
      </el-collapse-item>
      <el-collapse-item title="x轴设置" name="20">
        <el-form-item label="轴线颜色" prop="xLineColor">
          <ColorPicker
            v-model.trim="formData.xLineColor"
            @change="(val) => changed(val, 'xLineColor')"
          />
        </el-form-item>
        <el-form-item label="字体颜色" prop="xFontColor">
          <ColorPicker
            v-model.trim="formData.xFontColor"
            @change="(val) => changed(val, 'xFontColor')"
          />
        </el-form-item>
        <el-form-item label="文字大小" prop="xFontSize">
          <el-input-number
            v-model.trim="formData.xFontSize"
            size="default"
            style="width: 100%"
            controls-position="right"
            @change="changed($event, 'xFontSize')"
          />
        </el-form-item>
        <!-- <el-form-item label="分隔线" prop="xSplitLine">
          <el-switch v-model="formData.xSplitLine" @change="(val) => changed(val, 'xSplitLine')" />
        </el-form-item> -->
      </el-collapse-item>
      <el-collapse-item title="y轴设置" name="30">
        <!-- <el-form-item label="轴线颜色" prop="yLineColor">
          <ColorPicker
            v-model.trim="formData.yLineColor"
            @change="(val) => changed(val, 'yLineColor')"
          />
        </el-form-item> -->
        <el-form-item label="字体颜色" prop="yFontColor">
          <ColorPicker
            v-model.trim="formData.yFontColor"
            @change="(val) => changed(val, 'yFontColor')"
          />
        </el-form-item>
        <el-form-item label="文字大小" prop="yFontSize">
          <el-input-number
            v-model.trim="formData.yFontSize"
            size="default"
            style="width: 100%"
            controls-position="right"
            @change="changed($event, 'yFontSize')"
          />
        </el-form-item>
        <el-form-item label="分隔线" prop="ySplitLine">
          <el-switch v-model="formData.ySplitLine" @change="(val) => changed(val, 'ySplitLine')" />
        </el-form-item>
      </el-collapse-item>
    </el-collapse>
  </el-form>
</template>
<script lang="ts" setup>
import { reactive, watch } from 'vue'
import ColorPicker from '../../components/colorPicker.vue'

// 接收父组件传入的值
const props = defineProps<{
  modelValue: any
}>()

const emit = defineEmits(['update:modelValue', 'onChanged'])

const formData = reactive<any>({})

// const fontWeightOptions = ref([
//   { code: 'normal', name: '正常' },
//   { code: 'bold', name: '粗体' },
//   { code: 'bolder', name: '特粗体' },
//   { code: 'lighter', name: '细体' }
// ])

// const textAlignOptions = ref([
//   { code: 'center', name: '居中' },
//   { code: 'left', name: '左对齐' },
//   { code: 'right', name: '右对齐' }
// ])

watch(
  () => props.modelValue,
  (newVal) => {
    Object.assign(formData, newVal)
  },
  { immediate: true, deep: true }
)

const changed = (val: any, key: string) => {
  emit('update:modelValue', { ...formData })
  emit('onChanged', { key, val })
}
</script>
<style lang="scss" scoped></style>
